package com.guoxiaochen.springboot.controller;

import com.guoxiaochen.springboot.entity.User;
import com.guoxiaochen.springboot.service.UserServiceImp;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
public class UserController {

    @Resource
    private UserServiceImp usi;

    //以下是登录
    @RequestMapping(value = "/userLogin/submit", method = RequestMethod.POST)
    public String userLogin(HttpServletRequest request) {
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        if (usi.findUserByUsernameAndPassword(name, password) == null) {
            return "登陆失败！";
        }
        return "登陆成功！";
    }

    //以下是注册
    @RequestMapping(value = "/userRegister/submit", method = RequestMethod.POST)
    public String userRegister(HttpServletRequest request) {
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        User u = new User(name, password);
        return usi.addUser(u);
    }

}